package com.gnerv.battle.boot.module.base.autoconfigure;

import com.gnerv.battle.boot.module.base.service.CurrentAccountService;
import com.gnerv.battle.boot.module.base.service.PasswordService;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.util.Set;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Configuration
@ConditionalOnWebApplication
@ComponentScan(value = "com.gnerv.battle.boot.module.base")
@MapperScan("com.gnerv.battle.boot.**.mapper")
@EnableConfigurationProperties
public class BattleBaseAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnMissingClass(value = {"org.springframework.security.crypto.password.PasswordEncoder"})
    public PasswordService passwordService() {
        return source -> source;
    }

    @Bean
    @ConditionalOnMissingBean
    public CurrentAccountService currentAccountService(){
        return new CurrentAccountService() {
            @Override
            public String username() {
                return "";
            }

            @Override
            public String accountUkId() {
                return "";
            }

            @Override
            public Set<String> roleUkIdList() {
                return Set.of();
            }
        };
    }

}
